package cn.wolfcode.rule;

import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.AbstractLoadBalancerRule;
import com.netflix.loadbalancer.Server;

import java.util.List;
import java.util.Random;

public class ProductrandomRule extends AbstractLoadBalancerRule {
    @Override
    public void initWithNiwsConfig(IClientConfig iClientConfig) {

    }

    @Override
    public Server choose(Object o) {
        System.out.println("使用自己的负载均衡");
        List<Server> alllist = super.getLoadBalancer().getAllServers();
        int index = new Random().nextInt(alllist.size());
        return alllist.get(index);


    }
}
